package com.example.shop2021.controller;

import com.example.shop2021.DO.User;
import com.example.shop2021.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author guoli
 * @create 2021-11-20 4:15 下午
 */
@Controller
public class LoginController {
    @Autowired
    UserMapper userMapper;
    @RequestMapping("/toLoginPage")
    public String toLogin(){
        return "login";
    }
    @RequestMapping("/checkLogin")
    public String checkLogin(String username, String passwd, Model model, HttpServletRequest request){
        User u = userMapper.getUser(username,passwd);
        if(u==null){
            request.setAttribute("loginError","用户名或者密码错误");
            return "login";
        }
        request.getSession().setAttribute("loginUser",u);
        return "index";
    }
    @RequestMapping("/register")
    public String toRegister(){
        return "register";
    }
    @RequestMapping("/registerController")
    public String register(User u){
        System.out.println(u);
        return "login";
    }
}
